#include <cstdio>
#include <cstring>
char n[50];
int flag = 1;
int main()
{
    //洛谷P1106删数问题
    //原理:贪心
    //131415 3
    //最优解是删掉345
    //看看规律
    //1 3 1 4 1 5
    //平升降升降升
    //删掉的数全是波峰
    //所以删掉越靠前的波峰越是好的
    int t, b;
    scanf("%d", &t);
    while (t--)
    {
        scanf("%s %d", n, &b);
        int len = strlen(n);
        for (int i = 1; i <= b; i++)
        {
            for (int j = 0; j < len - 1; j++)
            {
                if (n[j] > n[j + 1]) //找波峰
                {
                    for (int k = j; k < len - 1; k++)
                    {
                        n[k] = n[k + 1];
                    }
                    break;
                }
            }
            len--;
        }
        for (int i = 0; i < len; i++)
        {
            printf("%c", n[i]);
        }
        printf("\n");
    }
}